<?php
//定时任务
class DoController extends AppController { 

    function beforeFilter() {
        parent::beforeFilter();
    }
    //
    function execfunc(){
        $act = $_GET['func'];  
        switch ($act) { 
            case 'commission':   
                break; 
            case 'video_play_num':  
                $this->loadModel('Video');  
                $this->loadModel('FuncSendLog');  
                $list = $this->Video->find('all',array('conditions'=>array('status'=>1)));  
                if(!empty($list)){
                    foreach ($list as $key => $value) {
                        $play_num=rand(20,200);  //随机20-200之间
                        //播放数+1 
                        $res=$this->Video->updateAll(array('Video.play_num'=>'`Video`.`play_num`+'.$play_num), array('Video.id'=>$value['Video']['id'])); 

                        if($res > 0){ 
                            $this->FuncSendLog->id=0;
                            $data['action']="execfunc:video_play_num"; 
                            $data['logDate']=date("Y-m-d",time());
                            $data['logTime'] = date("H:i:s",time()); 
                            $data['logString'] = "play_num增加:".$play_num."，info:".json_encode($value['Video']);   
                            $this->FuncSendLog->save($data);  
                        }
                    }
                }
                break; 
            case 'aide_num':   
                $this->loadModel('FuncSendLog');  
                $aide_num=rand(1,20);  //随机10-100之间
                $randNum=Ivf::aideCount('add',$aide_num);
                $data=[];
                $data['action']="execfunc:aide_num"; 
                $data['logDate']=date("Y-m-d",time());
                $data['logTime'] = date("H:i:s",time()); 
                $data['logString'] = "aide_num增加:".$aide_num."，now:".$randNum;   
                $this->FuncSendLog->save($data);   
                break; 
            case 'news_xml':   
                $this->loadModel('New');  

                $orderby=[];   
                $orderby['create_time']="desc";
                $conditions['status'] = 1;  
                $dataList =[]; 
                $dataList = $this->New->find('all',array('conditions' => $conditions,'order' => $orderby,'fields'=>array('update_time','id')));
                if(!empty($dataList)){
                    $dom = new DOMDocument('1.0','utf-8');//建立DOM对象  
                    $no1 = $dom->createElement('urlset');//创建普通节点：urlset
                    $no1->setAttribute('xmlns',"http://www.sitemaps.org/schemas/sitemap/0.9");
                    $no1->setAttribute('xmlns:mobile',"http://www.baidu.com/schemas/sitemap-mobile/1/");
                    $dom->appendChild($no1);//把urlset节点加入到DOM文档中   

                    foreach ($dataList as $key => $value) {
                        $no2 = $dom->createElement('url');
                        $no1->appendChild($no2); 

                        $no3 = $dom->createElement('loc');
                        $no2->appendChild($no3);
                        $no4 = $dom->createTextNode("http://www.ivf52.com/news/info/".$value['New']['id'].".html");
                        $no3->appendChild($no4);  


                        $no3 = $dom->createElement('mobile:mobile');
                        $no2->appendChild($no3); 
                        $no4 = $dom->createAttribute('type');
                        $no4->value = "pc,mobile";
                        $no3->appendChild($no4); 

                        $no3 = $dom->createElement('lastmod');
                        $no2->appendChild($no3);
                        $no4 = $dom->createTextNode(date("Y-m-d",strtotime($value['New']['update_time'])));
                        $no3->appendChild($no4);  


                        $no3 = $dom->createElement('changefreq');
                        $no2->appendChild($no3);
                        $no4 = $dom->createTextNode("monthly"); 
                        $no3->appendChild($no4); 


                        $no3 = $dom->createElement('priority');
                        $no2->appendChild($no3);
                        $no4 = $dom->createTextNode("0.8");
                        $no3->appendChild($no4);  
                    }
 

                    header('Content-type:text/html;charset=utf-8');
                    echo $dom->save('newslist.xml')?'存储成功':'存储失败';//存储为xml文档
                } 
                $this->loadModel('FuncSendLog');   
                $data=[];
                $data['action']="execfunc:news_xml"; 
                $data['logDate']=date("Y-m-d",time());
                $data['logTime'] = date("H:i:s",time()); 
                $data['logString'] = "生成xml:".json_encode($dataList);   
                $this->FuncSendLog->save($data);   
                break;
            default:
                break;
        } 
        die(); 
    }  
}